# 最长子串
def length_of_longest_substring(s: str) -> int:
    max_len = 0
    left = 0
    tag_mask = 0
    for i, c in enumerate(s):
        bit = to_bit(c)

        if tag_mask & bit > 0:
            max_len = max(max_len, i - left)

        while tag_mask & bit > 0:
            left += 1
            tag_mask ^= to_bit(s[left])

        tag_mask |= bit

    return max(max_len, len(s) - left)


def to_bit(c: str) -> int:
    return 1 << (ord(c) - 32)


# print(length_of_longest_substring('dvdf'))
# print(length_of_longest_substring('aab'))
# print(length_of_longest_substring('bbbbbb'))
# print(length_of_longest_substring('abcabcbb'))
print(length_of_longest_substring('abcabcbb'))
